<!--页面主要内容-->
<main class="lyear-layout-content">
  
  <div class="container-fluid p-t-15">
	
	<div class="row">
	  <div class="col-lg-12">
		<div class="card">
		  <div class="card-toolbar d-flex flex-column flex-md-row">
			<div class="toolbar-btn-action delpost restore">
			  <a class="btn btn-success" href="#!"><i class="mdi mdi-check"></i>恢复</a>
			</div>
			
			<form class="search-bar ml-md-auto" method="get" action="#!" role="form">
			  <input type="hidden" name="search_field" id="search-field" value="title" />
			  <div class="input-group ml-md-auto">
				<div class="input-group-prepend">
				  <button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" id="search-btn">标题</button>
				  <div class="dropdown-menu" style="">
					<a class="dropdown-item" href="#!" data-field="title">标题</a>
					<a class="dropdown-item" href="#!" data-field="cat_name">栏目</a>
				  </div>
				</div>
				<input type="text" class="form-control" name="keyword" placeholder="请输入名称">
			  </div>
			</form>
		  </div>
		  <div class="card-body">
			
			<div class="table-responsive">
			  <table class="table table-bordered" style="text-align: center;">
				<thead>
				  <tr>
					<th>
					  <div class="custom-control custom-checkbox">
						<input type="checkbox" class="custom-control-input" id="check-all">
						<label class="custom-control-label" for="check-all"></label>
					  </div>
					</th>
					<th>帖子标题</th>
					<th>悬赏积分</th>
					<th>创建时间</th>
					<th>帖子状态</th>
					<th>访问次数</th>
					<th>是否采纳</th>
					<th>操作</th>
				  </tr>
				</thead>
				<tbody>
				  {foreach $restorelist as $item}
					<tr >
					  <td>
					    <div class="custom-control custom-checkbox">
					  	<input type="checkbox" class="custom-control-input ids" name="ids[]" value="{$item.id}" id="{$item.id}">
					  	<label class="custom-control-label" for="{$item.id}"></label>
					    </div>
					  </td>
					  <td>{$item.title}</td>
					 
					  <td>{$item.point}</td>
					  <td>{$item.createtime}</td>
					  <td>
						  {if condition="$item.state == 1"}
						  	<span class="fly-jing">置顶</span>
						  {elseif condition="$item.state == 2"}
						  	<span class="fly-jing">精华</span>
						  {elseif condition="$item.state == 3"}
						  	<span class="fly-jing">热门</span>
						  {elseif condition="$item.state == 0"}
						  	<span class="fly-jing">普通</span>
						  {/if}
					  </td>
					  <td>
						  {$item.visit_count}
					  
					  </td>
					  <td>
						  {if condition="$item.accept"}
						      <span style="color: green;">已采纳</span>
						  {else /}
						  	  未采纳
						  {/if}
					  </td>
					  <td>
						  
						<div class="btn-group">
							<a class="btn btn-xs btn-default" href="{:url('home/index/info',['postid'=>$item.id])}" title="" data-toggle="tooltip" data-original-title="查看详情"><i class="mdi mdi-pencil"></i></a>
							<a class="btn btn-xs btn-default ajax-get confirm" href="#" data-toggle="tooltip" data-original-title="删除"><i class="mdi mdi-window-close"></i></a>
						</div>
					  </td>
					</tr>
				  {/foreach}
				  
				</tbody>
			  </table>
			</div>
			
			
			<!-- 分页 -->
			{$restorelist->render()}
			
		  </div>
		</div>
	  </div>
	
  </div>

</main>
<!--End 页面主要内容-->
<script type="text/javascript">
    
	
	function GetId() {
		// 存放id的数组
		let list = []
	
		$('input[name="ids[]"]:checked').each(function () {
			// console.log(item);
			list.push($(this).val())
		})
	
		return list
	}
	
    layui.use(['layer'],function(){
		layer = layui.layer
		
		// 恢复帖子
		$('.restore').click(function() {
		
			let str = GetId().join(',');
			
			console.log(str)
		
			$.ajax({
				type: 'post',
				url: `{:url('admin/post/restore')}`,
				data: {
					str
				},
				dataType: 'json',
				success: function(res) {
					if (res.code === 1) {
						layer.msg(res.msg, {
							icon: 1
						}, function() {
							location.href = 'postlist';
						})
					} else {
						layer.msg(res.msg, {
							icon: 5
						})
					}
				}
			})
		
		})
		
		
	})
</script>